<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>优惠券编号列表</title>
</head>
<body>

<div class="container">

        <div class="comm_content">

            <div  class="search-box">
                <form id="searchForm" class="form-inline" onsubmit="return false;">
                    <div style="position:relative">
                        <span>
                            优惠券编号：
                            <input id="code" class="form-control input-sm" type="text" name="code" value="" style="width:140px">
                        </span>

                        <span>
                            <input type="button" class="btn btn-primary" value="查询" onclick="coupon.search();">&nbsp;&nbsp;
                        </span>
                    </div>
                </form>
            </div>

            <table id="flex" style="display:none"></table>

        </div>


</div>

<script type="text/javascript">
    $("#flex").flexigrid({
        url:"/invokingAjax-backend/promotion/coupon.ajax?operFlg=8&couponID=<!--{$couponID}-->",
        dataType: "json",
        colModel : [
        	{display: "操作", width : 150, align: 'center'},
            {display: "优惠券编号", width : 150, align: 'center'},
            {display: "会员号", width : 150, align : 'left' },
            {display: "生成时间", width : 150, align: 'center'},
            {display: "截止日期", width : 120, align: 'center'},
            {display: "使用时间", width : 150, align: 'center'},
            {display: "订单编号", width : 150, align : 'center'},
            {display: "使用金额", width : 100, align : 'right'},
           	{display: "优惠券金额", width : 100, align : 'right'},
            {display: "使用状态", width : 100, align : 'right'}
        ],
        sortname: "createTime",
        sortorder: "asc",
        usepager: true,
        rp: 10,
        useRp: true
    });

    var coupon = {

        //查询
        search : function (){
        
        	//先查询优惠券编号是否有
        	var yhj = $('#code').val();
					$.ajax({
            url: "/invokingAjax-backend/promotion/coupon.ajax?operFlg=1",
            data: {
                code: yhj
            },
            type: "POST",
            success: function(data){
				data = eval('('+data+')');
				
				
				if(data.rows ==''){
				
				  	E.alert('优惠券编号不正确',2);
				
				
					
				}else{
           		 	var dt = $("#searchForm").serializeArray();
            		$("#flex").flexOptions({newp: 1, params: dt}).flexReload();
				}
				
            }            
        });
      

        }

    };
	function reset_yhj(id){
		yhj = id
		E.confirm("是否重置优惠券"+id, "chongzhi");
	
	}
	function chongzhi(){
		$.ajax({
            url: "/invokingAjax-backend/promotion/coupon.ajax?operFlg=9",
            data: {
                code: yhj
            },
            type: "POST",
            success: function(data){

				if(data==200){
				  E.alert('优惠券'+yhj+'重置成功.状态为\"未使用\"',2);
				  coupon.search();
				
				
				}else{
					alert('优惠券重置失败，请重新重置')
				}
				
            }            
        });
	
	
	}
</script>

</body>
</html>